<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>收藏列表</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../css/index.css"/>
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>		
		<script src="../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/vant.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="html5plus://ready"></script>
		<script src="../js/back.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			body{
				background-color: white;
			}
			header {
				padding: 15px 20px 5px 20px;
				background-color: red;
				color: white;
				margin-top: 0px;				
			}			
			#header-txt1 {
				margin-left: 35%;
			}
			#check{
				margin-left: 20px;
			}
			#card{
				width: 330px;
			}
			#right-text{
				background-color: red;
				height: 100px;
			}
			
		</style>
	</head>
	<body>
		<div id="app">
			<header>
				<van-row>
					<van-col span="4" >
						<span @click="goBack"><返回</span>
					</van-col>
					<van-col span="17">收藏宝贝</van-col>					
				</van-row>			
			</header>
			<!--头部结束-->	
					
			<section><!-- 页面主题 -->				
				<van-row>					
					<van-col v-for="(u,i) in Goods" span="24" style="margin:10px 0px" >
						<van-swipe-cell :right-width="65" ><!-- 滑动组件开始	 -->					    
							<van-cell-group><!-- 单个收藏商品开始 -->												
								<van-card
									v-bind:price="u.RealPrice" 
									v-bind:title="u.GoodsName" 
									v-bind:origin-price="u.MarketPrice" 
									v-bind:thumb="u.GoodsImageUrl"
									id="u.Id" 
									@click="GetId(i)"> 
									<img v-bind:src="u.GoodsImageUrl" 
									onerror="javascript:this.src='../img/product_default.jpg';onerror=null; "  
									slot="thumb">
								</van-cell-group><!-- 单个收藏商品结束 -->
						    <span slot="right" >
								<van-button type="danger" id="right-text" @click="onClose(u.GoodsId)">删除</van-button>
							</span><!-- 右边删除按钮 -->
						</van-swipe-cell><!-- 滑动组件结束	 -->
					</van-col> 
				</van-row>	
				
			</section>
			
			
		</div>
		
		
		<script type="text/javascript">
			var vm=new Vue({
				el:"#app",
				data:{
					checked:false,
					key:"",
					Goods:"",
					
				},
				mounted(){
					var _this=this;
					if (localStorage.getItem("keys") != null) {
						_this.key = localStorage.getItem("keys");
					}
					ajax({
						url:"http://dsapi.ysd3g.com/api/MyGoodsCollectList",
						dataType:"jsonp",
						data:{
							p:1,
							key:_this.key
						},
						success:function(res){
							if(res.Error==false){								
								console.log(res);
								vm.Goods=res.Data;
								console.log(res);								
							}else{								
								vm.$toast.fail(res.Msg)
							}
						}
					})
				},
				methods:{
					onClose(i) {						
						vm.$dialog.confirm({
							message: '确定删除吗？'
						}).then(() => {				//点击确认执行取消方法
						var _this=this;									
						ajax({
							url: "http://dsapi.ysd3g.com/api/cancelCollectGoods",
							dataType: "jsonp",
							data: {
								goodsId:i, 		//传id
								key:localStorage.getItem("keys")   //传key 
							},
							success: function(res) {
								if(res.Error==false){									
									var arr=vm.$toast.success("删除成功");									
									setTimeout(()=>{
										arr;
										plus.webview.currentWebview().reload(true); 
									},500)
								}else{
									vm.$toast.fail(res.Msg);
									console.log(vm.Goods[i].GoodsId)
									}
								}
							});
						}).catch(() => {
							instance.close();
						});					
					},
					goBack(){
						var arr=plus.webview.currentWebview();
						plus.webview.close(arr,"slide-out-right");
					},
					GetId: function(i) {
						plus.webview.create("../commodity-details/commodity.html", "commodity", {}, {
							lisprice: vm.Goods[i].RealPrice, //商品价格
							lisname: vm.Goods[i].GoodsName, //商品名称
							liscount: vm.Goods[i].SaleCount, //商品销量
							BrowseCount: vm.Goods[i].BrowseCount, //商品浏览量
							nId: vm.Goods[i].GoodsId //商品id,
							
						})						
						plus.webview.show("commodity","slide-in-right");
					},
				}
			})
		</script>			
	</body>
</html>
